package n.d.l.svn.web;

import n.d.l.svn.bean.Project;
import n.d.l.svn.bean.ResponseBean;
import n.d.l.svn.service.ProjectService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("svn")
public class SvnController {

	@Autowired
	private ProjectService projectService;
	
	/**
	 * 首页.
	 * @return
	 */
	@RequestMapping()
	public String svnIndex(Project project, Model model){
		model.addAttribute("pros", projectService.findList(project));
		return "index";
	}
	
	/**
	 * 编辑页.
	 * @param model
	 * @return
	 */
	@RequestMapping("te")
	public String editPage(int id, Model model){
		if(id>0){
			model.addAttribute("pro", projectService.getById(id));
		}
		return "svnEdit";
	}
	
	/**
	 * 编辑页.
	 * @param model
	 * @return
	 */
	@RequestMapping("e")
	@ResponseBody
	public ResponseBean edit(Project project){
		return projectService.edit(project);
	}
	
	/**
	 * 项目删除.
	 * @param id
	 * @return
	 */
	@RequestMapping("d")
	@ResponseBody
	public ResponseBean delById(int id){
		ResponseBean resp = new ResponseBean();
		if(projectService.delById(id)!=1){
			resp.setSuccess(false);
			resp.setMsg("删除失败");
		}
		return resp;
	}
}
